package com.breaker.kata.util;

import org.apache.commons.io.IOUtils;

import java.io.InputStream;
import java.nio.charset.StandardCharsets;

public class FileReader {
    private FileReader() {
    }

    public static String getContent(String fileName) {
        ClassLoader classLoader = FileReader.class.getClassLoader();
        InputStream stream = classLoader.getResourceAsStream(String.format("json/%s", fileName));
        try {
            if (stream == null) {
                throw new Exception("Cannot find file " + fileName);
            }
            return IOUtils.toString(stream, String.valueOf(StandardCharsets.UTF_8));
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(1);
        }
        return null;
    }
}
